﻿@using OSBLE.Models
@using OSBLE.Models.Assignments
@{
    List<Assignment> assignments = ViewBag.Assignments;
    int PastCount = ViewBag.PastCount;
    int PresentCount = ViewBag.PresentCount;
    int FutureCount = ViewBag.FutureCount;
    int DraftCount = ViewBag.DraftCount;
    bool isDraftAssignment = false, isFutureAssignment = false;
}

<table class="assignTable" cellspacing="0" id="assignmentListTable">
<tr>
    <th colspan="2" style="font-size:larger">Assignment</th>
    <th style="font-size:larger">Due Date</th>
    <th style="font-size:larger">Student Activity</th>
    <th style="font-size:larger; padding-left: 20px">Grading Progress</th>
</tr>

    @{
        for(int i = 0; i < assignments.Count; i++)
        {
            if (i == 0 && PresentCount > 0)
            {
                <tr>
                    <td colspan="100%" style="padding-right: 0; font-size: large" class="osbleColorBold">
                        Present (@PresentCount)
                    </td>
                </tr>
            }
            
            else if (i == (PresentCount) && PastCount > 0)
            {
         
                if (PresentCount > 0)
                {
                    //Only put a an empty row if there is something above this category
                    <tr>
                        <td style="padding-bottom: 10px">
                        </td>
                    </tr>
                }
                <tr>
                    <td colspan="100%" style="padding-right: 0; font-size: large" class="osbleColorBold">
                        Past (@PastCount)
                    </td>
                </tr>
            }
            else if (i == (PastCount + PresentCount) && FutureCount > 0)
            {
                isFutureAssignment = true;
                if ((PastCount + PresentCount) > 0)
                {
                    //Only put a an empty row if there is something above this category
                    <tr>
                        <td style="padding-bottom: 10px">
                        </td>
                    </tr>
                }
                <tr>
                    <td colspan="100%" style="padding-right: 0; font-size: large" class="osbleColorBold">
                        Future (@FutureCount)
                    </td>
                </tr>
            }
            else if (i == (PastCount + PresentCount + FutureCount) && DraftCount > 0)
            {
                isFutureAssignment = false;
                isDraftAssignment = true;
                if ((PastCount + PresentCount) > 0)
                {
                    //Only put a an empty row if there is something above this category
                    <tr>
                        <td style="padding-bottom: 10px">
                        </td>
                    </tr>
                }
                <tr>
                    <td colspan="100%" style="padding-right: 0; font-size: large" class="osbleColorBold">
                        Draft (@DraftCount)
                    </td>
                </tr>
            }

            //Now that headers are in place, inserting a assignment
            <tr class="checkeredRow"  >
                <td style="padding-right:0; white-space:nowrap"><!--Cell for icons-->
                    @if (assignments[i].IsDraft)
                    {
                        <a title="Click to Publish"  class="pointerOnMouseOver" href="/Assignment/ToggleDraft?assignmentID=@assignments[i].ID" >@Helpers.PublishButton()</a>
                    }
                    else
                    {
                        <a title="Click to Unpublish"  class="pointerOnMouseOver" href="/Assignment/ToggleDraft?assignmentID=@assignments[i].ID">@Helpers.UnPublishButton()</a>
                    }
                    <a title="Click to Edit" href="@Url.Action("Index", "Home", new { area = "AssignmentWizard", assignmentId = assignments[i].ID })">@Helpers.EditButton()</a>
                    @if(assignments[i].IsDraft)
                    {
                        <a title="Click to Delete" class="pointerOnMouseOver" onclick="openConfirmDeleteWindow(@assignments[i].ID)">@Helpers.DeleteButton()</a>
                    }
                    else
                    {
                        <a title="Must Unpublish Before Delete" class="pointerOnMouseOver">@Helpers.DeleteButtonDisabled()</a>
                    }
                </td>
                <td > <!--Cell for name-->
                    @Html.ActionLink(assignments[i].AssignmentName, "Index", "Home", new { area = "AssignmentDetails", assignmentId = assignments[i].ID }, null)
                </td>
                <td > <!--Cell for DueDate-->
                <time 
                class="utc-time"
                datetime="@Helpers.DateAsUnixTime(assignments[i].DueDate)" 
                data-original-date="@Helpers.RawDate(assignments[i].DueDate)" 
                data-date-format="MM/DD/YYYY hh:mm A">
                    @assignments[i].DueDate.ToShortDateString() @assignments[i].DueDate.ToShortTimeString() (UTC)
                </time>
                    
                </td>

                <!--Cell for Student Activity-->
                <td>                    
                    @if (isDraftAssignment)
                    {
                        
                    }
                    else if(assignments[i].Type == AssignmentTypes.CriticalReviewDiscussion || assignments[i].Type ==  AssignmentTypes.DiscussionAssignment)
                    {
                        @:@assignments[i].GetInitialPostsCount() of @ViewBag.TotalDiscussionPosters initial posts made.<br />
                        @:@assignments[i].GetPostsCount() total posts. @assignments[i].GetNewPostsCount(ViewBag.ActiveCourseUser.ID) unread posts.
                    }
                    else if (assignments[i].Type == AssignmentTypes.TeamEvaluation)
                    {
                        @:@assignments[i].GetCompletedTeamEvaluationsCount() of @assignments[i].GetTotalTeamEvaluationCount() evaluations completed.
                    }
                    else if (assignments[i].HasDeliverables && assignments[i].Type != AssignmentTypes.AnchoredDiscussion)
                    {
                        @:@assignments[i].GetSubmissionCount() of @assignments[i].AssignmentTeams.Count submissions received.<br />
                        @:@Html.ActionLink("Download all", "GetAllSubmissionsForAssignment", "FileHandler", new { assignmentID = assignments[i].ID }, new { onclick = "create_and_open_downloading_submission_dialog()" })
                    }
                </td>

                <!-- Cell for Grading Progress -->
                <td style="padding-left: 20px">
                    @if (assignments[i].HasRubric && !(isFutureAssignment || isDraftAssignment))
                    {
                    
                        if(assignments[i].AssignmentTeams.Count > 0)
                        {
                            @: @assignments[i].GetPublishedCount() of @assignments[i].AssignmentTeams.Count published.&nbsp @Html.ActionLink("Grade Now", "Index", "Rubric", new { assignmentId = assignments[i].ID, cuId = assignments[i].AssignmentTeams.FirstOrDefault().Team.TeamMembers.FirstOrDefault().CourseUserID }, new { })<br />
                        }                            
                            @: @assignments[i].GetSavedAsDraftCount() saved as draft.&nbsp @Html.ActionLink("Publish All", "PublishAllRubrics", "Assignment", new { area = "", assignmentId = assignments[i].ID }, new { })
                    
                    }
                </td>
            </tr>                
        }
    }
</table>